using System;
using SKBKontur.Serialization.Helpers;

namespace SKBKontur.Serialization.Binding
{
    public class EnumBinder : ScalarBinder
    {
        public EnumBinder(string columnName) : base(columnName)
        {
        }

        public EnumBinder()
        {
        }

        public override byte[] SerializeValue(object value)
        {
            return Enum.Format(value.GetType(), value, "g").ToUtf8ByteArray();
        }

        public override object UnserializeValue(Type type, byte[] data)
        {
            return Enum.Parse(type, data.ToUtf8Str());
        }
    }
}